#include<iostream>
#include<cstring>
#include<deque>
#define x first
#define y second

using namespace std;
typedef pair<int,int> PAI;
const int N = 510;
int n , m , k;
int d[N][N];
char g[N][N];
bool st[N][N];

/*

1
3 5
\\/\\
\\///
/\\\\

*/

int bfs()
{
    deque<PAI> q;
    q.push_back({0 , 0});
    memset(d , 0x3f , sizeof(d));
    memset(st , 0 ,sizeof(st));
    d[0][0] = 0;
    char cs[5] = "\\/\\/";
    int dx[] = {-1 , -1 , 1 , 1} , dy[] = {-1 ,1 ,1, -1};
    int ix[] = {-1 , -1 , 0 ,0} , iy[] = {-1 , 0 , 0 , -1};
    
    while(q.size())
    {
        PAI t = q.front();
        q.pop_front();
        
        if(t.x == n && t.y == m) return d[n][m];
        
        if(st[t.x][t.y]) continue;
        st[t.x][t.y] = true;
        for(int i = 0 ; i<4 ; ++i)
        {
            int a = t.x + dx[i] , b = t.y + dy[i];
            if(a < 0 || a > n || b < 0 || b >m) continue;
            int gx = t.x + ix[i] , gy = t.y + iy[i];
            int dis = d[t.x][t.y] + (g[gx][gy] != cs[i]);
            if(dis < d[a][b])
            {
                d[a][b] = dis;
                if(g[gx][gy] == cs[i]) q.push_front({a,b});
                else q.push_back({a,b});
            }
        }
    }
    
    return -1;
}

int main()
{
    scanf("%d" , &k);
    while(k--)
    {
        scanf("%d%d" , &n , &m);
        for(int i = 0 ; i <n ; ++i) scanf("%s" , g[i]);
        
        if((m + n) & 1) printf("NO SOLUTION\n");
        else printf("%d\n" , bfs());
    }   
    printf("C ܳ mother fucker\n");
    system("pause");
}